package com.test4;

import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.*;

import java.util.stream.Stream;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class JunitTest2 {
    @Test
    @Order(1)
    void editLoginTest() {
        System.out.println("editLoginTest");
    }
    @Test
    @Order(2)
    void AddOneOfIndex() {
        System.out.println("AddOneOfIndex");
    }

    @Test
    @Order(3)
    void test() {
        System.out.println("test");
    }

    @ParameterizedTest
    @ValueSource(strings = {"lucky", "bob", "zhangsan"})
    void ValueSourceTest(String name) {
        System.out.println(name);
    }

    @ParameterizedTest
    @CsvSource({"lucky, 20", "bob, 35", "zhangsan, 50"})
    void CsvSourceTest(String name, int age) {
        System.out.println("name=" + name + ", age=" + age);
    }

    @ParameterizedTest
    @CsvFileSource(files = "D:\\temp\\name.csv")
    void CsvFileSourceTests(String name, int age) {
        System.out.println("name=" + name + ", age=" + age);
    }

    // 通过动态方法来提供数据源
    @ParameterizedTest
    @MethodSource("dynamic")
    void dynamicTest(String name, int age) {
        System.out.println("name=" + name + ", age=" + age);
    }

    static Stream<Arguments> dynamic() {
        // 构造动态参数
        String[] arr = new String[5];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = System.currentTimeMillis() + "frost";
        }
        // 不同数据类型需要用Stream<Arguments>传参，相同类型则直接返回数据类型
        return Stream.of(
                Arguments.arguments(arr[0], 10),
                Arguments.arguments(arr[1], 10),
                Arguments.arguments(arr[2], 10),
                Arguments.arguments(arr[3], 10),
                Arguments.arguments(arr[4], 10)
        );
    }
}
